#include "stdafx.h"

#include "Timer.h"

#include "TransitionState.h"
#include "Menus\Label.h"

#include "States\TransitionStateUserInterface.h"

using namespace std;

TransitionState::TransitionState(u32 durationInSec, shared_ptr<GameStateObject> pGameStateObject) : m_timer(nullptr),
                                                                                                    m_duration(durationInSec),
                                                                                                    m_pGameStateObject(pGameStateObject)
{
}

TransitionState::~TransitionState()
{
}

bool TransitionState::Init(GameEngine& gameEngine)
{
    m_timer = make_shared<Timer>();
    m_timer->start();

    m_userInterface = make_shared<TransitionStateUserInterface>(gameEngine.GetGUISystem(), m_pGameStateObject);
    m_userInterface->Init();


    return true;
}

void TransitionState::PreUpdate(ZeEngine::GameEngine& gameEngine)
{

}

bool TransitionState::Update(ZeEngine::GameEngine& gameEngine)
{
    //Once we are done go back to the previous state
    if (m_timer->getElapsedTimeInSec() > m_duration)
    {
        gameEngine.PopState();
    }
    return true;
}

void TransitionState::PostUpdate(ZeEngine::GameEngine& gameEngine)
{
}

void TransitionState::Destroy(ZeEngine::GameEngine& gameEngine)
{
    m_userInterface->Destroy(gameEngine);
    m_timer->stop();
}